package com.htandroid.htandroid.webservice;

import android.util.Xml;

import com.htandroid.htandroid.entity.Htzc_Pvouch;
import com.htandroid.htandroid.entity.Htzc_Pvouchs;

import org.xmlpull.v1.XmlPullParser;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.ArrayList;

public class XMLHtzcPvouchslist {

    /**
     * 解析评论xml信息
     *
     * @param result
     * @return
     */
    public static ArrayList<Htzc_Pvouchs> paraseCommentInfors(String result) {
        ArrayList<Htzc_Pvouchs> list = new ArrayList<Htzc_Pvouchs>();
        //字符转换成字节流
        InputStream inputStream = new ByteArrayInputStream(result.getBytes());
        XmlPullParser parser = Xml.newPullParser();
        try {
            parser.setInput(inputStream, "UTF-8");
            int eventType = parser.getEventType();
            Htzc_Pvouchs info = new Htzc_Pvouchs();

            while (eventType != XmlPullParser.END_DOCUMENT) {
                switch (eventType) {
                    case XmlPullParser.START_DOCUMENT:// 文档开始事件,可以进行数据初始化处理
                        break;
                    case XmlPullParser.START_TAG:// 开始元素事件
                        String name = parser.getName();
                        if (name.equalsIgnoreCase("Htzc_Pvouchs")) {
                            info = new Htzc_Pvouchs();
                        } else {
                            eventType = parser.next();
                            if (name.equalsIgnoreCase("autoid")) {
                                info.setAutoid(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cvouchid")) {
                                info.setCvouchid(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("scardnum")) {
                                info.setScardnum(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("sassetnum")) {
                                info.setSassetnum(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("sassetname")) {
                                info.setSassetname(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("dblvalue")) {
                                info.setDblvalue(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("sdeptnum")) {
                                info.setSdeptnum(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("sdeptname")) {
                                info.setSdeptname(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("sStyle")) {
                                info.setsStyle(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("ssite")) {
                                info.setSsite(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("cuser")) {
                                info.setCuser(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("lbuildnum")) {
                                info.setLbuildnum(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("lnum")) {
                                info.setLnum(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("ldiffnum")) {
                                info.setLdiffnum(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("creason")) {
                                info.setCreason(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("dpdate")) {
                                info.setDpdate(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("isup")) {
                                info.setIsup(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("succount")) {
                                info.setSuccount(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("zccheckeddate")) {
                                info.setZccheckeddate(string2null(parser.getText()));
                            } else if (name.equalsIgnoreCase("zccheckedname")) {
                                info.setZccheckedname(string2null(parser.getText()));
                            }
                        }
                        break;
                    case XmlPullParser.END_TAG:// 结束元素事件
                        if (parser.getName().equalsIgnoreCase("Htzc_Pvouchs")) {
                            list.add(info);
                            info = null;
                        }
                        break;
                }
                eventType = parser.next();
            }
            inputStream.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    //函数作用是把null 转为空
    public static String string2null(String str) {
        String rtn = "";
        if (str == null || str.equals("null") || str.equals("anyType{}")) {
            rtn = "";
        } else {
            rtn = str;
        }
        return rtn;
    }

}  
